package net.aiion.weave.impl.xml.events;

import net.aiion.weave.spi.xml.events.CharactersXmlEvent;

public class CharactersXmlEventImpl extends XmlEventImpl implements CharactersXmlEvent
{
    private final String characterData;
    private final int characterDataType;

    public CharactersXmlEventImpl(final String aData) {
        this(aData, TYPE_PARSED_CHARACTER_DATA);
    }

    public CharactersXmlEventImpl(final String aCharacterData, final int aCharacterDataType) {
        characterData = aCharacterData;
        characterDataType = aCharacterDataType;
    }

    @Override
    public int getType() {
        return CHARACTERS;
    }

    public String getData() {
        return characterData;
    }

    @Override
    public boolean isUnparsedCharacterData() {
        return characterDataType == TYPE_UNPARSED_CHARACTER_DATA;
    }

    @Override
    public boolean isParsedCharacterData() {
        return characterDataType == TYPE_PARSED_CHARACTER_DATA;
    }

    @Override
    public boolean isRawCharacterData() {
        return characterDataType == TYPE_RAW_CHARACTER_DATA;
    }

    @Override
    public int getCharacterDataType() {
        return characterDataType;
    }

    @Override
    public boolean isWhitespace() {
        return characterData.trim().isEmpty();
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder();
        builder.append("XmlCharactersImpl[data=");
        builder.append(characterData);
        builder.append("]");
        return builder.toString();
    }

}
